package com.mengniu.commerce.collect.service.impl.member;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mengniu.commerce.collect.service.IPushStrategy;
import com.mengniu.commerce.collect.util.WeiMengResultUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @Description: 微盟会员创建事件推送
* @Param:
* @return:
* @Author: zfw
* @Date: 2023/12/3
* @Date: 14:15
*/
@Slf4j
@Service("weimob_crm.customer_create" + IPushStrategy.BASE_NAME)
@RequiredArgsConstructor
public class WmMemberInfoPushServiceImpl implements IPushStrategy {

    @Autowired
    private WmMemberServiceImpl wmMemberService;

    /***
    * @Description: 接收新增会员消息,调用同步接口将数据创建到蒙牛
    * @Param: [entity]
    * @return: java.lang.Object
    * @Author: zfw
    * @Date: 2023/12/3
    * @Date: 14:16
    */
    @Override
    public Object push(Long bosId,String entity) {
        log.info("微盟创建会员事件推送entity:{}",entity);
        JSONObject jsonObject = JSONObject.parseObject(entity);
        JSONArray widList = jsonObject.getJSONArray("widList");
        List<String> lsit = widList.toJavaList(String.class);
        wmMemberService.createMemberByMsg(bosId,lsit);

        return WeiMengResultUtil.restResult(0,"success");
    }
}
